package com.smart.community.commons.monitor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.concurrent.atomic.AtomicLong;

/**
 * 日志监控服务
 * @author Wu.Liang
 * @since 2024-12-19
 * @version 1.0.0
 */
@Slf4j
@Service
public class LogMonitoringService {
    
    private final AtomicLong errorCount = new AtomicLong(0);
    private final AtomicLong warningCount = new AtomicLong(0);
    private final AtomicLong infoCount = new AtomicLong(0);
    
    /**
     * 记录错误日志
     * 
     * @param message 错误消息
     * @param throwable 异常
     */
    public void logError(String message, Throwable throwable) {
        errorCount.incrementAndGet();
        log.error(message, throwable);
    }
    
    /**
     * 记录警告日志
     * 
     * @param message 警告消息
     */
    public void logWarning(String message) {
        warningCount.incrementAndGet();
        log.warn(message);
    }
    
    /**
     * 记录信息日志
     * 
     * @param message 信息消息
     */
    public void logInfo(String message) {
        infoCount.incrementAndGet();
        log.info(message);
    }
    
    /**
     * 获取错误日志数量
     * 
     * @return 错误日志数量
     */
    public long getErrorCount() {
        return errorCount.get();
    }
    
    /**
     * 获取警告日志数量
     * 
     * @return 警告日志数量
     */
    public long getWarningCount() {
        return warningCount.get();
    }
    
    /**
     * 获取信息日志数量
     * 
     * @return 信息日志数量
     */
    public long getInfoCount() {
        return infoCount.get();
    }
    
    /**
     * 重置计数器
     */
    public void resetCounters() {
        errorCount.set(0);
        warningCount.set(0);
        infoCount.set(0);
    }
}
